package com.tanhua.server.contoller;

import com.tan.model.domain.Verification;
import com.tanhua.server.service.PhoneService;
import com.tanhua.server.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/users/phone")
public class PhoneController {
    @Autowired
    private PhoneService phoneService;
    @PostMapping("/sendVerificationCode")
    public ResponseEntity sendVerificationCode(){
      phoneService.sendMsg();

        return ResponseEntity.ok(null);
    }
    @PostMapping("/checkVerificationCode")
    public ResponseEntity checkVerificationCode(@RequestBody Map map){
      String verificationCode = (String)  map.get("verificationCode");
        Verification verification=new Verification();
        verification.setVerification(phoneService.checkVerificationCode(verificationCode));
        return ResponseEntity.ok(verification);
    }
    @PostMapping
    public ResponseEntity changePhone(@RequestBody Map map){
       String phone = (String) map.get("phone");
       phoneService.changePhone(phone);
       return ResponseEntity.ok(null);

    }
}
